package br.uefs.dexa.rfframework.gui.config.dialogs;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;

import br.uefs.dexa.rfframework.gui.utils.ScreenUtils;

public abstract class ConfigDialog extends JDialog {
	
	
	private static final long serialVersionUID = 8718836179969004896L;

	private static final int MINIMUM_WIDTH = 500;
	
	private static final int MINIMUM_HEIGTH = 500;
	
	protected static final int BUTTON_WIDTH = 100;
	
	protected static final int BUTTON_HEIGTH = 30;
	
	protected static final int GENERAL_PADDING = 10;
	
	private final JPanel contentPanel = new JPanel();
	
	private ConfigDialogTopPanel topPanel;
	
	private ConfigDialogBottomPanel bottomPanel;
	
	private JPanel mainPanel;
	
	
	
	
	public ConfigDialog()
	{
		init();
		setMinimumSize();
		setCentralPosition();
	}
	
	private void init()
	{
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setContentPane(contentPanel);
		initTopPanel();
		initMainPanel();
		initBottomPanel();
		addPanels();
	}
	
	private void setMinimumSize()
	{
		super.setMinimumSize(new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGTH));
	}
	
	private void setCentralPosition()
	{
		super.setLocation( (int) (ScreenUtils.getHalfWidth() - Math.round((double) ((double) getSize().getWidth() / 2.0 ))), (int) (ScreenUtils.getHalfHeigth() - Math.round((double) ((double) getSize().getHeight() / 2.0 ))));
	}
	
	private void initTopPanel()
	{
		topPanel = new ConfigDialogTopPanel(this);
		topPanel.setBackground(Color.WHITE);
		topPanel.setPreferredSize(new Dimension(MINIMUM_WIDTH, 70));
		topPanel.setBorder(BorderFactory.createEmptyBorder(GENERAL_PADDING, GENERAL_PADDING, GENERAL_PADDING, GENERAL_PADDING));
	}
	
	private void initMainPanel()
	{
		mainPanel = new JPanel();
		mainPanel.setBorder(BorderFactory.createEmptyBorder(GENERAL_PADDING, GENERAL_PADDING, GENERAL_PADDING, GENERAL_PADDING));
	}
	
	private void initBottomPanel()
	{
		bottomPanel = new ConfigDialogBottomPanel(this);
		bottomPanel.setPreferredSize(new Dimension(MINIMUM_WIDTH, 70));
		bottomPanel.setBorder(BorderFactory.createEmptyBorder(GENERAL_PADDING, GENERAL_PADDING, GENERAL_PADDING, GENERAL_PADDING));
	}
	
	private void addPanels()
	{
		contentPanel.setLayout(new GridBagLayout());
		
		JSeparator separator1 = new JSeparator();
		JSeparator separator2 = new JSeparator();
		
		separator1.setPreferredSize(new Dimension(MINIMUM_WIDTH, 1));
		separator2.setPreferredSize(new Dimension(MINIMUM_WIDTH, 1));
		
		GridBagConstraints c1 = new GridBagConstraints();
		GridBagConstraints c2 = new GridBagConstraints();
		GridBagConstraints c3 = new GridBagConstraints();
		GridBagConstraints c4 = new GridBagConstraints();
		GridBagConstraints c5 = new GridBagConstraints();
		
		
		c1.gridx = 0;
		c1.gridy = 0;
		c1.anchor = GridBagConstraints.PAGE_START;
		c1.fill = GridBagConstraints.HORIZONTAL;
		
		c2.gridx = 0;
		c2.gridy = 1;
		c2.fill = GridBagConstraints.HORIZONTAL;
		
		c3.gridx = 0;
		c3.gridy = 2;
		c3.weighty = 1;
		c3.fill = GridBagConstraints.BOTH;
		
		c4.gridx = 0;
		c4.gridy = 3;
		c4.fill = GridBagConstraints.HORIZONTAL;
		
		c5.gridx = 0;
		c5.gridy = 4;
		c5.fill = GridBagConstraints.HORIZONTAL;

				
		getContentPane().add(topPanel, c1);
		getContentPane().add(separator1, c2);
		getContentPane().add(mainPanel, c3);
		getContentPane().add(separator2, c4);
		getContentPane().add(bottomPanel, c5);
		
	}
	
	
	
	
	protected void setDescriptio(String description)
	{
		topPanel.setDescrition(description);
	}
	
	protected JPanel getMainPanel()
	{
		return mainPanel;
	}
	
	
	public abstract void okButtonAction();
	
	
	public abstract void cancelButtonAction();
	
	
	
	public static void main(String[] args) {
		//ConfigDialog cd = new ConfigDialog();
	}

}




